<?
  class dbList{
   var $cnt=0;
   var $perPage=0;
   var $page=0;
   var $end=0;
   var $startSelect=0;
   var $endSelect=0;
   var $smarty="";
   var $db="";
   var $list="";
   var $filter="";
   var $table="";

   function dbList($db,$table,$filter="",$pg=1,$ppg=10){
    $this->db=$db;
    $this->filter=$filter;
    $this->table=$table;
    $this->cnt = $this->countData();
    $this->perPage = $ppg;
    $this->page = $pg ? $pg : 1;
    $this->page = $this->page > ceil($this->cnt/($this->perPage)) ? ceil($this->cnt/($this->perPage)) : $this->page;
    $this->end=ceil($this->cnt/$this->perPage);

    $this->startSelect = ($this->page-1)*$this->perPage;
    $this->startSelect = $this->startSelect > $this->cnt ? 0 : $this->startSelect;
    $this->startSelect = $this->startSelect < 0 ? 0 : $this->startSelect;

    $this->endSelect = $this->startSelect + $this->perPage;
    $this->endSelect = $this->endSelect > $this->cnt ? $this->cnt : $this->endSelect;

   }

   function loadData(){
    $db=$this->db;
    $sql="SELECT * FROM ".$this->table." WHERE 1=1 {$this->filter} LIMIT {$this->startSelect},{$this->perPage}" ;
    $db->query($sql);

    $this->list=$db->getArray();
   }

   function countData(){
    $db=$this->db;
    $sql="SELECT count(*) as cnt FROM ".$this->table." WHERE 1=1 {$this->filter}";
    $db->query($sql);
    $db->next_record();
    $cnt = $db->f("cnt");
    return $cnt;
   }


   function assign(&$smarty){

     $smarty->assign("page", $this->page);
     $smarty->assign("end", ceil($this->cnt/$this->perPage));
     $smarty->assign("startSelect", $this->startSelect+1);
     $smarty->assign("endSelect", $this->endSelect);
     $smarty->assign("separator","?");
     $smarty->assign("records",$this->list);

   }
   function dump(){
    print_r($this->list);
   }
  }
  class dbCustomList{
   var $cnt=0;
   var $perPage=0;
   var $page=0;
   var $end=0;
   var $startSelect=0;
   var $endSelect=0;
   var $smarty="";
   var $db="";
   var $list="";
   var $sql="";
   var $sql_cnt="";
   var $table="";

   function dbCustomList($db,$sql,$sql_cnt,$pg=1,$ppg=10){
    $this->db=$db;
    $this->sql_cnt=$sql_cnt;
    $this->cnt = $this->countData();
    $this->perPage = $ppg;
    $this->page = $pg ? $pg : 1;
    $this->page = $this->page > ceil($this->cnt/($this->perPage)) ? ceil($this->cnt/($this->perPage)) : $this->page;
    $this->end=ceil($this->cnt/$this->perPage);

    $this->startSelect = ($this->page-1)*$this->perPage;
    $this->startSelect = $this->startSelect > $this->cnt ? 0 : $this->startSelect;
    $this->startSelect = $this->startSelect < 0 ? 0 : $this->startSelect;

    $this->endSelect = $this->startSelect + $this->perPage;
    $this->endSelect = $this->endSelect > $this->cnt ? $this->cnt : $this->endSelect;

    $this->sql=$sql." LIMIT {$this->startSelect},{$this->perPage}";
   }

   function loadData(){
    $db=$this->db;
    $db->query($this->sql);

    $this->list=$db->getArray();
   }

   function countData(){
    $db=$this->db;
    $db->query($this->sql_cnt);
    $db->next_record();
    $cnt = $db->f("cnt");
    return $cnt;
   }


   function assign(&$smarty){

     $smarty->assign("page", $this->page);
     $smarty->assign("end", ceil($this->cnt/$this->perPage));
     $smarty->assign("startSelect", $this->startSelect+1);
     $smarty->assign("endSelect", $this->endSelect);
     $smarty->assign("separator","?");
     $smarty->assign("records",$this->list);

   }
   function dump(){
    print_r($this->list);
   }
  }

?>